<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调色板</title>
    <style>
        *{margin: 0;padding:0;box-sizing: border-box}
        .container{
            width: 400px;
            min-height: 400px;
            border:solid 1px #ddd;
            margin: 50px auto;
        }

        .show{
            height: 300px;
            background: rgb(36, 123, 145);
        }
        .control{
            padding: 10px 15px;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //声明组件   
        class Draw extends React.Component{

            state = {
                r: 0,
                g: 0,
                b: 0
            }

            render(){
                //解构赋值
                let {r,g,b} = this.state;
                return <div className="container">
                        <div className="show" style={{background: `rgb(${r},${g},${b})`}}></div>
                        <div className="control">
                            R: <input type="range" min="0" max="255" value={r} onChange={this.saveData('r')}/><span>{r}</span><br />
                            G: <input type="range" min="0" max="255" value={g} onChange={this.saveData('g')}/><span>{g}</span><br />
                            B: <input type="range" min="0" max="255" value={b} onChange={this.saveData('b')}/><span>{b}</span><br />
                        </div>
                    </div>
            }

            saveData = (type) => {
                return (e) => {
                    this.setState({
                        [type]: e.target.value
                    })
                }
            }
        }

        ReactDOM.render(<Draw />, document.querySelector("#root"));
    </script>
</body>
</html>